<template>
  <c-dialog ref="dialog" title="项目过程评估" :open-fun="openFun" width="70vw" @open="openHandle" @close="closeHandle">
    <Score ref="score" :show-title="false" :detail="detail" />
    <div class="btn-container">
      <c-button @click="cancelHandle">取消</c-button>
      <c-button type="primary" @click="confirmHandle">确认</c-button>
    </div>
  </c-dialog>
</template>
<script>
import { postConstUnitAssessScore } from '@/api/decorate'
import Score from '../../components/score'
export default {
  name: 'ScoreDialog',
  components: {
    Score
  },
  props: {
    selData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      rawDetail: {}
    }
  },
  computed: {
    detail() {
      return this.selData.length === 1 ? this.selData[0] : {}
    }
  },
  created() {
  },
  methods: {
    openFun() {
      if (!this.singleJudge(this.selData, '项目过程评估', true)) {
        return false
      }
      // 自装不能 项目评估
      if (this.detail.nature === 'PRIVATES') {
        this.$message.warning('自装不能进行项目过程评估！')
        return false
      }
      if (!this.detail.constUnitCode) {
        this.$message.warning('没有施工单位不能进行项目过程评估！')
        return false
      }
      // 项目过程评估：步骤值在“装修进场”（含装修进场）之后，装修完工(含)，可操作项目过程评估
      const schedule = this.detail.schedule
      if (!['D', 'E', 'F', 'G', 'H'].includes(schedule)) {
        this.$message.warning('该任务不能进行项目过程评估！')
        return false
      }
      return true
    },
    openHandle() {
      this.rawDetail = this.detail
    },
    closeHandle() {
      this.rawDetail = {}
    },
    confirmHandle() {
      return this.$refs.score.genData().then(data => {
        return postConstUnitAssessScore(data).then(res => {
          this.$message.success('操作成功！')
          this.$refs.dialog.visible = false
          this.$emit('on-success')
        })
      })
    },
    cancelHandle() {
      this.$refs.dialog.visible = false
    }
  }
}
</script>
